package controller

import (
	"camera_app/entity"
	"fmt"

	"github.com/gin-gonic/gin"
)

type StaticController struct{}

func NewStaticController() *StaticController {
	return &StaticController{}
}

func (sc *StaticController) GetImg(ctx *gin.Context) {
	username := ctx.Param("username")
	date := ctx.Param("date")
	file := ctx.Param("file")
	curUser, _ := ctx.Get("user")
	curUserEntity := curUser.(entity.User)
	if curUserEntity.Username != username {
		ctx.JSON(403, gin.H{
			"msg": "无权限",
		})
		return
	}
	fmt.Println("/tmp/" + username + "/" + date + "/" + file)
	ctx.File("/tmp/" + username + "/" + date + "/" + file)
}
